layui.use(['layer', 'table'], function () {
    let table = layui.table,

        layer = layui.layer;
    layui.layer.load(0, {shade: [0.5, '#fff']});
    /*查询所有公告的信息*/
    table.render({
        elem: '#final-version-table'
        , toolbar: '#task-table-toolbar'
        , height: 700
        , url: "/getPaper"
        , where: {queryKey: '', userName: USERNAME, state: '终稿',type: 3}
        , cols: [
            [ //标题栏
                {field: 'bh', title: '编号', width: 90, align: 'center', sort: true},
                {field: 'title', title: '标题', align: 'center'},
                {field: 'sno', title: '学号', width: 140, align: 'center'},
                {field: 'sname', title: '姓名', width: 110, align: 'center'},
                {
                    field: 'title1', title: '所属学院', width: 130, align: 'center', templet: function (res) {
                        return res.title1.collegeName;
                    }
                },
                {
                    field: 'title1', title: '所属专业', width: 150, align: 'center', templet: function (res) {
                        return res.title1.majorName;
                    }
                },
                {
                    field: 'title1', title: '指导老师', width: 110, align: 'center', templet: function (res) {
                        return res.title1.tName;
                    }
                },
                {
                    field: 'title1', title: '老师工号', width: 130, align: 'center', templet: function (res) {
                        return res.title1.tno;
                    }
                },
                {
                    field: 'task', title: '检查结果', width: 130, align: 'center', templet: function (res) {
                        if (res.stageCheck === null) {
                            return '<span style="color: #999999">无结果</span>'
                        }else if (res.stageCheck.result === null || res.stageCheck.result === ''){
                            return '<span style="color: #999999">无结果</span>'
                        }else if (parseFloat(res.stageCheck.result) < 0.30 ){
                            return '<span style="color: #009f95">' + res.stageCheck.result +'</span>';
                        }else if (parseFloat(res.stageCheck.result) > 0.30 ){
                            return '<span style="color: red">' + res.stageCheck.result +'</span>';
                        }else {
                            return '<span style="color: #999999">无结果</span>'
                        }
                    }
                },
                {
                    field: 'state', title: '论文阶段', width: 130, align: 'center', templet: function (res) {
                        if (res.state === '终稿') {
                            return '<span style="color: #009688">终稿</span>'
                        } else {
                            return '<span style="color: #999999">' + res.state + '</span>'
                        }

                    }
                },
                {
                    field: 'task', title: '初稿状态', width: 140, align: 'center', templet: function (res) {
                        if (res.stageCheck === null) {
                            return '<span style="color: red">待提交</span>'
                        } else {
                            if (res.stageCheck.state === null || res.stageCheck.state === '') {
                                return '<span style="color: red">待提交</span>'
                            } else if (res.stageCheck.state === '审核中') {
                                return '<span style="color: blue">审核中</span>'
                            } else if (res.stageCheck.state === '审核完成') {
                                return '<span style="color: #009688">审核完成</span>'
                            } else {
                                return '<span style="color: red">待提交</span>'
                            }
                        }
                    }
                },

                {title: '课题详情', align: 'center', width: 120, toolbar: '#task-table-tool'},
                {title: '审核结果', align: 'center', width: 120, toolbar: '#assignment-table-tool'},
                {field: 'title1', title: '课题来源', width: 120, align: 'center', hide: true},
                {field: 'stageCheck', title: '课题类别', width: 100, align: 'center', hide: true},
            ]
        ]
        // ,skin: 'line' //表格风格
        , even: true
        , page: true
        , limits: [11, 22, 33]
        , limit: 11
        , text: {
            none: '<div class="layui-anim layui-anim-scaleSpring"  style="margin-top: 150px"><i class="layui-icon" style="color: #009f95;font-size: 150px;border-bottom: #009f95 solid 2px;padding:15px;margin-top: 50px" >&#xe664;</i><br>' +
                '<br><br><br><br><div class="layui-text" style="font-size: 25px;margin-top: 25px;color: #009f95">好像没有没找到数据呢</div></div>'
            ,
            error: '<div style="margin-top: 150px"><i class="layui-icon"  style="color: #009f95;font-size: 150px;border-bottom: #009f95 solid 2px;padding:15px;margin-top: 50px" >&#xe664;</i><br>' +
                '<br><div class="layui-text" style="font-size: 25px;margin-top: 25px;color: #009f95">好像没有出错了呢</div></div>'
        }
    });


    //监听表头事件  监听对象  allUSer
    table.on('toolbar(final-version-table)', function (obj) {

        //查询事件
        if (obj.event === 'query') {  //按关键字搜索事件
            let queryKey = $('#queryKey').val().trim(); //获取搜索的关键字
            if (queryKey === null || queryKey === '') {
                layer.msg('请输入要查询工号/姓名/课题名称', {offset: '260px', time: 1500, anim: 6});
                return false;
            }
            layer.alert(queryKey);
            table.reload('final-version-table', {
                where: {queryKey: queryKey, userName: USERNAME, state: '终稿',type: 3} //设定异步数据接口的额外参数
            });

        } else if (obj.event === 'queryAll') {  //查询全部
            table.reload('final-version-table', {
                where: {queryKey: '', userName: USERNAME, state: '终稿',type: 3} //设定异步数据接口的额外参数
            });
        }
    });


    /*监听操作栏事件*/
    table.on('tool(final-version-table)', function (obj) {
        let data = obj.data;  //json格式的数据
        if (obj.event === 'taskDetail') {  //编辑事件
            layer.open({
                type: 1
                , offset: 100
                , skin: 'layui-layer-rim'
                , area: ['740px', '600px']
                , content: $("#task-detail")
                , title: '学生课题详情内容'
                , success: function (layero) {
                    let mask = $(".layui-layer-shade");
                    mask.appendTo(layero.parent());
                    /*设置回显数据*/
                    setTaskDetail(data);
                }
                , end: function () {
                    $("#task-detail").css("display", 'none');
                }
            });
        } else if (obj.event === 'finalVersionDetail') {  //终稿审核详情
            if (data.stageCheck === null) {
                layer.msg('该学生终稿还未提交', {offset: '250px', time: 1500, anim: 6});
                return false
            }
            if (data.stageCheck.state === '审核中') {
                layer.msg('该学生终稿还在审核中', {offset: '250px', time: 1500, anim: 6});
                return false;
            }
            layer.alert('查看定核终稿的详情');
        }
    });


    $("#query-online").click(function () {
        layer.alert('你选择了在线预览');
    });

    //在线批注
    $("#postil-online").click(function () {
        layer.alert('在线批注');
    });


    layui.layer.closeAll('loading');


});



